'''
Created on May 23, 2010

@author: shemit
'''

from javax.swing import JFrame as frame
from java.awt import Dimension as dimension
from javax.swing import JTabbedPane as tabbed_pane
from javax.swing import JPanel as panel
from java.awt.event import MouseAdapter as mouseadapter
from java.awt import Graphics as graphics
from java.awt import Graphics2D as graphics2d
from java.awt import Color as color
from skeleton import skeleton


class env:
    skeletons = []
    def __init__(self, gravity):
        self.gravity = gravity
    def addSkeleton(self, skeleton):
        self.skeletons.append(skeleton)
    def animate(self, graphics):
        for skeleton in self.skeletons:
            skeleton.animate(graphics, self.gravity)   
            r = skeleton.bones["hanger"].newrot
            print "rot is" + str(r)



class view_panel(panel):
    class animmouseadapter(mouseadapter):
        def __init__(self, vpanel):
            self.vpanel = vpanel
        def mouseClicked(self, e):
            self.vpanel.repaint()
            print "should be repainting"
    
    def __init__(self):
        self.environment = env(9.8)
        self.environment.addSkeleton(skeleton())
        self.addMouseListener(self.animmouseadapter(self))
        
    def paintComponent(self, g):
        g.setColor(color.black)
        g.fillRect(0, 0, self.getWidth(), self.getHeight())
        self.environment.animate(g)
        
class options_panel(panel):
    def __init__(self):
        pass
    
class tab_panel(tabbed_pane):
    def __init__(self):
        self.setPreferredSize(dimension(300, 300))

class view_frame(frame):
    '''
    Creates a frame to view the muscle model
    '''
    def __init__(self):
        '''
        Constructor
        '''
        self.setVisible(1)
        tabs = tab_panel()
        self.view = view_panel()
        self.opts = options_panel()
        tabs.add(self.view, "View Render")
        tabs.add(self.opts, "Options")
        self.add(tabs)
        self.setDefaultCloseOperation(self.EXIT_ON_CLOSE)
        self.pack()